package com.lee.demo1.business;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.lee.demo1.dao.InstructonsMapper;
import com.lee.demo1.dao.TagMapper;
import com.lee.demo1.domain.Instructons;
import com.lee.demo1.domain.Tag;

/**
 * 
 * @author leopad
 *
 */
@Service
public class SearchBusiness {
	
	private static Logger logger = LoggerFactory.getLogger(SearchBusiness.class);
	
	
	@Value("${solr.server1.url}")
	private String searchServer1Url;

	@Resource
	private TagMapper tagMapper;
	
	@Resource
	private InstructonsMapper instructonsMapper;
	
	public String getSearchServer1Url() {
		return searchServer1Url;
	}

	public void setSearchServer1Url(String searchServer1Url) {
		this.searchServer1Url = searchServer1Url;
	}
	
	/**
	 * 供页面输入框匹配使用
	 * @return
	 */
	@Cacheable("CompleteDataCache")
	public String getCompleteData(){
		
		List<Tag> tags = tagMapper.selectTagAndSort();
		StringBuilder sb = new StringBuilder();
		for (Tag tag : tags) {
			sb.append(tag.getTagName());
			sb.append("\n");
		}
		
		List<Instructons> insts = instructonsMapper.selectForSearch();
		
		for(Instructons ins : insts) {
			if(StringUtils.isNotBlank(ins.getDrugNames())){
				sb.append(ins.getDrugNames());
				sb.append("\n");
			}
			if(StringUtils.isNotBlank(ins.getDrugNamesEn())){
				sb.append(ins.getDrugNamesEn());
				sb.append("\n");
			}
			if(StringUtils.isNotBlank(ins.getDrugNamesPy())){
				sb.append(ins.getDrugNamesPy());
				sb.append("\n");
			}
		}
		return sb.toString();
  	}

}
